package com.lyf.network.practice.nio;

import org.junit.Test;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

/**
 *
 * Buffer + Channel + Selector
 *
 * @author LYF
 * @date 2022/6/23
 */
public class ThreeElement {

    @Test
    public void test(){
        /*
        1.层级关系
       public abstract class ByteBuffer
    extends Buffer
      implements Comparable<ByteBuffer>

        2.存储结构
        final byte[] hb;                  // Non-null only for heap buffers
       final int offset;
       boolean isReadOnly;

        3.基本API
        public static ByteBuffer allocate(int capacity) {
        if (capacity < 0)
            throw createCapacityException(capacity);
        return new HeapByteBuffer(capacity, capacity, null);
    }
         */
        ByteBuffer buffer = ByteBuffer.allocate(10);
        //
        buffer.put("hello".getBytes(StandardCharsets.UTF_8));
        byte[] bytes = new byte[10];
//        buffer.get(bytes);
//        System.out.println(new String(bytes));
        System.out.println((char) buffer.get()+"::"+buffer.getChar());



    }

}
